// Car类
class Car(val licensePlate: String, val brand: String, val color: String, val price: Double) {
  def drive(): Unit = {
    println("Driving the car.")
  }

  def park(): Unit = {
    println("Parking the car.")
  }

  def refuel(): Unit = {
    println("Refueling the car.")
  }
}

// ElectricCar类（继承自Car）
class ElectricCar(licensePlate: String, brand: String, color: String, price: Double,
                  val batteryCapacity: Double, var range: Double) extends Car(licensePlate, brand, color, price) {

  // 重写drive方法
  override def drive(): Unit = {
    if (range > 0) {
      println("Driving the electric car.")
      range -= 10 // 举例减少续航里程
    } else {
      println("Not enough battery to drive.")
    }
  }

  // 充电方法
  def charge(): Unit = {
    println("Charging the electric car.")
    range = batteryCapacity // 充电后续航里程重置为电池容量
  }
}
/*
// 测试
object Main extends App {
  // 创建汽车和电动汽车对象
  val car1 = new Car("ABC123", "Toyota", "Blue", 25000.0)
  val electricCar1 = new ElectricCar("XYZ456", "Tesla", "Red", 80000.0, 75.0, 300.0)

  // 驾驶和充电
  car1.drive()
  electricCar1.drive()
  electricCar1.charge()

  // 打印汽车信息
  println("\nCar Information:")
  println(s"Car 1: ${car1.brand} - ${car1.color}")
  println(s"Electric Car 1: ${electricCar1.brand} - ${electricCar1.color} - Range: ${electricCar1.range} miles")
}
*/
